﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SchoolManagementSystem.Controls;
using CoreData;

namespace SchoolManagementSystem.Details
{
    public partial class CustomerUC : DetailUC
    {
        public CustomerUC()
        {
            InitializeComponent();
            this.ObjectName = "Khách hàng";
            this.Code = "Customer";
            this.Type = new Customer();

            comboBoxEdit_sex.Properties.Items.Add("Nam");
            comboBoxEdit_sex.Properties.Items.Add("Nữ");
        }
        protected override long DetailDisplay()
        {
            Customer data = new Customer();
            if (ID > 0)
            {
                data = (Customer)RegisterService.RegisterServices.CustomerService.GetByID(ID);

            }

            txtname.Text = data.Name;
            txtnote.Text = data.Description;
            txtcode.Text = data.Code;
            txtaddress.Text = data.Address;
            txtcmnd.Text = data.IndentifyNumber;
            txtemail.Text = data.Email;
            txtnumberphone.Text = data.Phone;
            ckactive.Checked = data.Active;
            comboBoxEdit_sex.EditValue = data.Sex;


            return ID;

        }

        protected override long Save()
        {
            Customer data = new Customer();
            if (ID > 0)
            {
                data = (Customer)RegisterService.RegisterServices.CustomerService.GetByID(ID);

            }

            data.Code = txtcode.Text;
            data.Name = txtname.Text;
            data.Description = txtnote.Text;
            data.Active = ckactive.Checked;
            data.Sex = comboBoxEdit_sex.EditValue.ToString();
            data.Phone = txtnumberphone.Text;
            data.IndentifyNumber = txtcmnd.Text;
            data.Address = txtaddress.Text;
            data.Email = txtemail.Text;

            ID = RegisterService.RegisterServices.TeacherService.Save(data, ref ErrorMess);

            return ID;
        }


        public override bool Delete(long SelectedID)
        {

            var check = RegisterService.RegisterServices.CustomerService.GetByID(SelectedID);
            //if (check != null)
            //{
            //    ErrorMess = "Vui lòng xóa liên kết giáo viên này với lớp học trước khi xóa giáo viên";
            //    return false;
            //}
            //else
            //{
                //return RegisterService.RegisterServices.BranchService.Delete(RegisterService.RegisterServices.BranchService.GetByID(SelectedID));
                return RegisterService.RegisterServices.TeacherService.UpdateIsDelete(RegisterService.RegisterServices.TeacherService.GetByID(SelectedID));
            //}

        }

        private void CustomerUC_Load(object sender, EventArgs e)
        {
            AddTextChanged(groupControl1.Controls);
        }
    }
}
